'use strict';

/**
 * Config for the router
 */
angular.module('app')
    .run(
        ['$rootScope', '$state', '$stateParams','$cookieStore',
            function ($rootScope, $state, $stateParams,$cookieStore) {
                $rootScope.$state = $state;
                $rootScope.$stateParams = $stateParams;
                $rootScope.userObj = $cookieStore.get('cy__admin');
            }
        ]
    )
    .config(
        ['$stateProvider', '$urlRouterProvider',
            function ($stateProvider, $urlRouterProvider) {

                $urlRouterProvider
                    .otherwise('/app/dashboard-v1');
                $stateProvider
                    .state('app', {
                        abstract: true,
                        url: '/app',
                        templateUrl: 'tpl/app.html',
                        controller: function ($rootScope, $cookieStore, $state) {
                            if ($cookieStore.get('cy__admin')) {
                                $rootScope.userObj = $cookieStore.get('cy__admin');
                            } else {
                                $state.go('access.signin');
                            }
                        }
                    })
                    .state('app.dashboard-v1', {
                        url: '/dashboard-v1',
                        templateUrl: 'tpl/app_dashboard_v1.html'
                    })


                    //member
                    .state('app.member', {
                        url: '/member',
                        template: '<div ui-view class="fade-in"></div>',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('toaster').then(
                                        function () {
                                            return ;
                                        }
                                    );
                                }
                            ]
                        }
                    })
                    .state('app.member.fram', {
                        url: '/fram/{previous:int}',
                        templateUrl: 'tpl/member_fram.html',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('toaster').then(
                                        function () {
                                            return $ocLazyLoad.load('js/controllers/member_fram.js');
                                        }
                                    );
                                }
                            ]
                        }
                    })
                    .state('app.member.list', {
                        url: '/list',
                        templateUrl: 'tpl/member_list.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load('js/controllers/member_list.js');
                                }
                            ]
                        }
                    })

                    //fund
                    .state('app.fund', {
                        url: '/fund',
                        template: '<div ui-view class="fade-in"></div>',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('toaster').then(
                                        function () {
                                            return ;
                                        }
                                    );
                                }
                            ]
                        }
                    })
                    .state('app.fund.member', {
                        url: '/member',
                        templateUrl: 'tpl/fund_member.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load('js/controllers/fund_member.js');
                                }
                            ]
                        }
                    })
                    .state('app.fund.list', {
                        url: '/list',
                        templateUrl: 'tpl/fund_list.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load('js/controllers/fund_list.js');
                                }
                            ]
                        }
                    })




                    .state('access', {
                        url: '/access',
                        template: '<div ui-view class="fade-in-right-big smooth"></div>'
                    })
                    .state('access.signin', {
                        url: '/signin',
                        templateUrl: 'tpl/page_signin.html',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['js/controllers/signin.js']);
                                }
                            ]
                        }
                    })



            }
        ]
    );